﻿using System.Collections.Generic;

namespace Downloader
{
    public class Subject
    {
        private readonly List<IObserver> _observers = new List<IObserver>();

        /// <summary>
        /// Registers the observer.
        /// </summary>
        /// <param name="observer">The observer.</param>
        public void RegisterObserver(IObserver observer)
        {
            if (_observers.Contains(observer))
            {
                return;
            }

            _observers.Add(observer);
        }

        /// <summary>
        /// Notifies the observers.
        /// </summary>
        public void NotifyObservers()
        {
            _observers.ForEach(observer => observer.Notify(this));
        }
    }
}
